<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <title>更新密</title>
    <link href="../static/css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
    <link href="../static/css/font-awesome.min.css" th:href="@{/css/font-awesome.min.css}" rel="stylesheet"/>
    <link href="../static/css/login.min.css" th:href="@{/css/login.min.css}" rel="stylesheet"/>
    <!-- 360浏览器急速模式 -->
    <meta name="renderer" content="webkit">
    <!-- 避免IE使用兼容模式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="shortcut icon" href="../static/favicon.ico" th:href="@{favicon.ico}"/>
    <style type="text/css">
        label.error { position:inherit;  }
        .signinpanel {
            color: #1a2226;
        }
    </style>
    <script>
        if(window.top!==window.self){alert('未登录或登录超时。请重新登录');window.top.location=window.location};
    </script>
</head>
<body class="signin">
    <div class="signinpanel">
        <div class="row">

            <div class="col-sm-6">
                <form id="signupForm" autocomplete="off">
                    <h4 class="no-margins">密码更新：</h4>
                    <p class="m-t-md"></p>
                    <input type="text"     name="username" class="form-control uname"  placeholder="用户名" value="" />
                    <input type="password" name="password" class="form-control pword"  placeholder="旧密码" value="" />
                    <input type="password" name="password2" class="form-control pword"  placeholder="新密码" value="" />
                    <input type="hidden" name="seCode" th:value="${seCode}" />

                    <button class="btn btn-success btn-block" id="btnSubmit" data-loading="正在提交，请稍候...">保存</button>
                </form>
            </div>
        </div>
        <div class="signup-footer">
            <div class="pull-left">
                文件管理系统 Copyright © 2021-2022  All Rights Reserved. <br>
            </div>
        </div>
    </div>
    <script th:inline="javascript"> var ctx = [[@{/}]]; </script>
<!-- 全局js -->
    <script src="../static/jquery.min.js" th:src="@{/jquery.min.js}"></script>
    <script src="../static/validate/jquery.validate.min.js" th:src="@{/validate/jquery.validate.min.js}"></script>
    <script src="../static/layer/layer.min.js" th:src="@{/layer/layer.min.js}"></script>

    <script>

    $(function() {
        validateRule();

    });

    $.validator.setDefaults({
        submitHandler: function() {
            login();
        }
    });

    function login() {
        var username = trim($("input[name='username']").val());
        var password = trim($("input[name='password']").val());
        var password2 = trim($("input[name='password2']").val());
        var seCode = trim($("input[name='seCode']").val());
        $.ajax({
            type: "post",
            url: "/repwd/update",
            data: {
                "uname": username,
                "oldPwd": password,
                "newPwd": password2,
                "seCode": seCode
            },
            success: function(r) {
                if (r == web_status.SUCCESS) {
                    // location.href = ctx + 'index';
                    $(".form-control").val("");
                    alert("密码修改成功！请稍候重新登录文件管理系统。");
                } else {
                    alert(r);
                }
            }
        });
        // 空格截取
        function trim(value) {
            if (value == null) {
                return "";
            }
            return value.toString().replace(/(^\s*)|(\s*$)|\r|\n/g, "");
        }
    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                username: {
                    required: true
                },
                password: {
                    required: true
                },
                password2: {
                    required: true
                }
            },
            messages: {
                username: {
                    required: icon + "请输入您的用户名",
                },
                password: {
                    required: icon + "请输入您的旧密码",
                },
                password2: {
                    required: icon + "请输入您的新密码",
                }
            }
        })
    }

    function getParam(paramName) {
        var reg = new RegExp("(^|&)" + paramName + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return decodeURI(r[2]);
        return null;
    }
    /** 消息状态码 */
    web_status = {
        SUCCESS: 0,
        FAIL: 500,
        WARNING: 301
    };
</script>
</body>
</html>
